Skip to content

feat(java): add mesh scheduling worker#359

Merged
pratyush618 merged 6 commits into
masterfrom
feat/java-mesh
Jul 5, 2026
Merged

feat(java): add mesh scheduling worker#359
pratyush618 merged 6 commits into
masterfrom
feat/java-mesh

Conversation

@pratyush618

@pratyush618 pratyush618 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

What

Binds the decentralized mesh scheduler (crates/taskito-mesh) into the Java SDK behind a new mesh cargo feature. A worker started with MeshOptions interposes a MeshNode (SWIM gossip + consistent-hash affinity + TCP work-stealing) between the scheduler and the dispatcher, and exposes a live MeshClusterInfo snapshot. The DB stays the source of truth; scheduler and dispatcher stay mesh-unaware — same bridge pattern as the Python and Node shells.

How

  • Rust mesh feature (crates/taskito-java): optional taskito-mesh dep; #[cfg(feature = "mesh")] mod mesh. spawn_mesh builds the node, starts gossip + steal-server inside a runtime.enter() guard (they call the free tokio::spawn), and runs the bridge loop: scheduler output → affinity-sorted local deque (+ steal from busy peers) → dispatcher channel. WorkerOptions.mesh_config (raw JSON) selects the path; without it the plain scheduler loop is byte-identical.
  • JNI: NativeWorker.meshClusterInfo returns a JSON ClusterInfo or null; stop signals the node so gossip/steal tasks exit instead of lingering. WorkerHandle holds the node for its lifetime.
  • Java: Worker.Builder.mesh(MeshOptions); MeshOptions (record-backed builder, port/seeds/buffer/intervals, range-validated); MeshClusterInfo; Worker.meshClusterInfo()Optional.
  • Build: cargoBuild now passes --features postgres,redis,workflows,mesh; Cargo.lock updated for the new dep edge.

Testing

  • MeshWorkerTest — a solo mesh worker runs a job end-to-end through the bridge and reports peerCount == 0; a plain worker reports no cluster; out-of-range port rejected.
  • Full ./gradlew build on JDK 22: mesh (3), FFM (2), transport-parity (2) all ran (not skipped); Spotless/Checkstyle + suite green. Rust fmt/clippy --all-features clean; generic-crate leakage tripwire confirms taskito-mesh stays free of jni/pyo3/napi.

Summary by CodeRabbit

  • New Features
    • Added mesh worker support for Java, including configuration, startup, and runtime status reporting.
    • Introduced a new cluster snapshot API so workers can report mesh information when enabled.
    • Added Java-side mesh configuration options for tuning connectivity, buffering, stealing, and encryption.
  • Bug Fixes
    • Workers now shut down mesh-related processing cleanly when stopping.
  • Tests
    • Added coverage for mesh-enabled job processing, empty mesh status on standard workers, and invalid port validation.

@github-actions github-actions Bot added the rust label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 26 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b97cfb1-cbdc-4e53-89c4-358436a13627

📥 Commits

Reviewing files that changed from the base of the PR and between b018371 and c1c688c.

📒 Files selected for processing (4)
  • .github/workflows/ci-java.yml
  • .github/workflows/publish-java.yml
  • crates/taskito-java/src/mesh.rs
  • crates/taskito-java/src/worker.rs
📝 Walkthrough

Walkthrough

This PR adds an optional "mesh" clustering feature to taskito-java, gating a new taskito-mesh dependency behind a Cargo feature. It introduces a scheduling bridge that forwards jobs through a mesh-aware local deque, spawns gossip/steal-server tasks, and exposes cluster info via a new JNI entry point. The Java SDK gains MeshOptions, MeshClusterInfo, worker builder support, and tests, with the Gradle build updated to compile the native library with the mesh feature enabled.

Changes

Mesh scheduling feature

Layer / File(s) Summary
Cargo feature and mesh config field
crates/taskito-java/Cargo.toml, crates/taskito-java/src/lib.rs, crates/taskito-java/src/convert.rs
Adds an optional mesh Cargo feature/dependency, a conditional mod mesh; declaration, and an optional mesh_config JSON field on WorkerOptions.
Mesh scheduling bridge implementation
crates/taskito-java/src/mesh.rs
Implements spawn_mesh and run_mesh_bridge, constructing a MeshNode, starting gossip/steal-server tasks, and forwarding jobs from the scheduler through the mesh deque to the dispatcher with stealing and prefetching.
Worker lifecycle integration and JNI entry point
crates/taskito-java/src/worker.rs
Stores an optional mesh node in WorkerHandle, conditionally routes job dispatch through spawn_mesh, signals mesh shutdown on stop, and adds the meshClusterInfo JNI function.
Java JNI mesh cluster info plumbing
sdks/java/.../internal/NativeWorker.java, sdks/java/.../internal/JniWorkerControl.java, sdks/java/.../spi/WorkerControl.java
Declares the native meshClusterInfo method, implements meshClusterInfoJson() in JniWorkerControl, and adds a default Optional-returning method to WorkerControl.
MeshOptions and MeshClusterInfo public API
sdks/java/.../worker/MeshOptions.java, sdks/java/.../worker/MeshClusterInfo.java
Adds the MeshClusterInfo record and a builder-based MeshOptions class that validates inputs and serializes to a native JSON config.
Worker mesh integration and build wiring
sdks/java/.../worker/Worker.java, sdks/java/build.gradle.kts, sdks/java/src/test/.../MeshWorkerTest.java
Adds Worker.meshClusterInfo() and Builder.mesh(), encodes mesh config into worker options, enables the mesh Cargo feature in the Gradle native build, and adds tests covering mesh job processing, non-mesh behavior, and port validation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant JavaWorker as Java Worker
  participant JNI as NativeWorker (JNI)
  participant SpawnMesh as spawn_mesh
  participant Bridge as run_mesh_bridge
  participant MeshNode

  JavaWorker->>JNI: start(options with meshConfig)
  JNI->>SpawnMesh: spawn_mesh(config_json, worker_id, queues)
  SpawnMesh->>MeshNode: construct + start gossip/steal-server
  SpawnMesh->>Bridge: spawn run_mesh_bridge
  loop job processing
    Bridge->>MeshNode: drain local deque
    MeshNode-->>Bridge: forward jobs to dispatcher
    Bridge->>MeshNode: steal from peers if low
  end
  JavaWorker->>JNI: meshClusterInfo(handle)
  JNI->>MeshNode: cluster_info()
  MeshNode-->>JNI: JSON snapshot
  JNI-->>JavaWorker: Optional<MeshClusterInfo>
Loading

Possibly related PRs

  • ByteVeda/taskito#300: Both PRs modify crates/taskito-java/src/worker.rs, extending the JNI worker lifecycle and WorkerHandle with new dispatch/bridge functionality.

Suggested labels: ci

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding mesh scheduling support for the Java worker.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/java-mesh

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
sdks/java/src/main/java/org/byteveda/taskito/worker/MeshOptions.java (1)

96-185: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add range validation to remaining mesh option setters.

Only port() validates its range; affinityWeight, virtualNodes, localBufferCapacity, maxStealBatch, stealThreshold, and stealRateLimit accept arbitrary/negative values that are passed straight into toConfigJson() and on to the native mesh node. The javadoc for affinityWeight documents a [0.0, 1.0] contract that isn't enforced, and a non-positive virtualNodes could be a source of native-side failures in the consistent-hash ring.

🛡️ Example validation additions
         public Builder affinityWeight(double affinityWeight) {
+            if (affinityWeight < 0.0 || affinityWeight > 1.0) {
+                throw new IllegalArgumentException("affinityWeight must be in [0.0, 1.0]");
+            }
             this.affinityWeight = affinityWeight;
             return this;
         }
...
         public Builder virtualNodes(int virtualNodes) {
+            if (virtualNodes <= 0) {
+                throw new IllegalArgumentException("virtualNodes must be positive");
+            }
             this.virtualNodes = virtualNodes;
             return this;
         }

Please confirm whether the taskito-mesh crate already guards these values server-side; if not, defensive validation here avoids surfacing a native-side crash as a confusing failure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sdks/java/src/main/java/org/byteveda/taskito/worker/MeshOptions.java` around
lines 96 - 185, Add defensive range checks in MeshOptions.Builder for the
remaining setters that currently accept unchecked values. Enforce the documented
[0.0, 1.0] contract in affinityWeight(), and validate that virtualNodes,
localBufferCapacity, maxStealBatch, stealThreshold, and stealRateLimit are
non-negative or strictly positive as appropriate before storing them. Keep the
checks alongside the existing port() validation in the Builder so invalid values
are rejected before toConfigJson() serializes them and before the native mesh
node sees them.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/taskito-java/src/mesh.rs`:
- Around line 30-35: MeshConfig parsing in the mesh setup is swallowing
malformed or incompatible JSON by falling back to defaults. In the mesh
initialization path where serde_json::from_str(config_json) is used, replace the
silent fallback with explicit error handling: log the parse failure with enough
context (for example, in the mesh scheduling enablement flow before the existing
log::info! call) and then choose an intentional fallback or abort path. Keep the
logging and config usage tied to the same MeshConfig parsing point so failures
are visible instead of silently running with default gossip_port and seeds.
- Around line 48-59: The background task in mesh.rs that uses
`tokio::join!(gossip, steal_server)` is discarding failures from the gossip and
steal-server workers. Update the async block that spawns these tasks to inspect
the `JoinError`/panic results from both tasks and log any failure with enough
context before exiting or propagating it. Use the existing `runtime.spawn`,
`gossip`, and `steal_server` symbols to locate the worker-lifetime task wrapper
and add failure handling there.

In `@crates/taskito-java/src/worker.rs`:
- Around line 100-123: The mesh setup in worker.rs is passing `capacity as u16`,
which can silently truncate when `channel_capacity` exceeds `u16::MAX`. Update
the `spawn_mesh` call path in `worker` to convert `capacity` safely by
saturating at `u16::MAX` (or otherwise clamping) before handing it to
`crate::mesh::spawn_mesh`, so the advertised threads/load-balancing value
remains correct.

---

Nitpick comments:
In `@sdks/java/src/main/java/org/byteveda/taskito/worker/MeshOptions.java`:
- Around line 96-185: Add defensive range checks in MeshOptions.Builder for the
remaining setters that currently accept unchecked values. Enforce the documented
[0.0, 1.0] contract in affinityWeight(), and validate that virtualNodes,
localBufferCapacity, maxStealBatch, stealThreshold, and stealRateLimit are
non-negative or strictly positive as appropriate before storing them. Keep the
checks alongside the existing port() validation in the Builder so invalid values
are rejected before toConfigJson() serializes them and before the native mesh
node sees them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 023d2032-5dd8-40b9-8162-395cfebf36eb

📥 Commits

Reviewing files that changed from the base of the PR and between 03213e5 and b018371.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • crates/taskito-java/Cargo.toml
  • crates/taskito-java/src/convert.rs
  • crates/taskito-java/src/lib.rs
  • crates/taskito-java/src/mesh.rs
  • crates/taskito-java/src/worker.rs
  • sdks/java/build.gradle.kts
  • sdks/java/src/main/java/org/byteveda/taskito/internal/JniWorkerControl.java
  • sdks/java/src/main/java/org/byteveda/taskito/internal/NativeWorker.java
  • sdks/java/src/main/java/org/byteveda/taskito/spi/WorkerControl.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/MeshClusterInfo.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/MeshOptions.java
  • sdks/java/src/main/java/org/byteveda/taskito/worker/Worker.java
  • sdks/java/src/test/java/org/byteveda/taskito/MeshWorkerTest.java

Comment thread crates/taskito-java/src/mesh.rs Outdated
Comment thread crates/taskito-java/src/mesh.rs
Comment thread crates/taskito-java/src/worker.rs
@github-actions github-actions Bot added the ci label Jul 2, 2026
@pratyush618
pratyush618 merged commit 86deec0 into master Jul 5, 2026
36 checks passed
@pratyush618
pratyush618 deleted the feat/java-mesh branch July 5, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant